package com;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.PassengerMapper;
import com.pojo.Passenger;
import com.utils.MyBatisUtils;
import org.junit.Test;

import java.util.List;

/**
 * @author YDW
 * projectName:project2202_3
 * time:2022/4/28 15:57
 * description:
 */
public class testMybatis {
    @Test
    public void testPage(){
        //startPage(当前页，每页条数) 开始分页
        PageHelper.startPage(1,3);
        PassengerMapper mapper = MyBatisUtils.getMapper(PassengerMapper.class);
        List<Passenger> passengers = mapper.queryAll();
        PageInfo<Passenger> pageInfo=new PageInfo<>(passengers);
        System.out.println("总条数:"+pageInfo.getTotal());
        System.out.println("总页数:"+pageInfo.getPages());
        System.out.println("数据:"+pageInfo.getList());
        System.out.println("当前页:"+pageInfo.getPageNum());
        System.out.println("每页条数:"+pageInfo.getPageSize());
        System.out.println("上一页:"+pageInfo.getPrePage());
        System.out.println("下一页:"+pageInfo.getNextPage());
        System.out.println("末行:"+pageInfo.getEndRow());
        System.out.println("-----------------------------");
        System.out.println(pageInfo);
    }
    @Test
    public void queryAll(){

        PassengerMapper mapper = MyBatisUtils.getMapper(PassengerMapper.class);
        List<Passenger> passengers = mapper.queryAll();
        for (Passenger passenger : passengers) {
            System.out.println(passenger);
            System.out.println(passenger.getPassport());
        }
    }
}
